package com.spring.biz;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.spring.dao.LogDAO;
import com.spring.dao.UserDAO;
import com.spring.model.Log;
import com.spring.model.User;

@Component("userBiz")
public class UserManager {

	private UserDAO userDAO;
	private LogDAO logDAO;
	private List<String> lists;

	private Map<String, Object> map;

	private Properties props;
	
	// @Transactional
	public void add(User u){
		userDAO.save(u);
		Log log = new Log();
		log.setTime(new Date().toString());
		log.setMsg("A user is saved");
		logDAO.save(log);
	}
	@PreDestroy
	public void destroy() {
		System.out.println("destroy");
	}

	public List<String> getLists() {
		return lists;
	}

	public LogDAO getLogDAO() {
		return logDAO;
	}

	public Map<String, Object> getMap() {
		return map;
	}

	public Properties getProps() {
		return props;
	}

	public UserDAO getUserDAO() {
		return userDAO;
	}

	@PostConstruct
	public void init() {
		System.out.println("init");
	}

	public void setLists(List<String> lists) {
		this.lists = lists;
	}

	@Resource
	public void setLogDAO(LogDAO logDAO) {
		this.logDAO = logDAO;
	}

	public void setMap(Map<String, Object> map) {
		this.map = map;
	}

	public void setProps(Properties props) {
		this.props = props;
	}

	@Resource(name="userDAO")
	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	public String toString() {
		String returnStr;
		returnStr = "lists:" + lists.size() + "map:" + map.size() + "props:"
				+ props.size();
		return returnStr;
	}
}
